package de.slothsoft.network;

import java.awt.BorderLayout;
import java.io.PrintStream;

import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import de.slothsoft.commons.swing.util.JEditorPaneUtil;

public abstract class AbstractNetworkPanel extends JPanel {

	private static final long serialVersionUID = 1L;

	private JEditorPane outputPane;
	private PrintStream out;

	public AbstractNetworkPanel() {
		createLayout();
	}

	private void createLayout() {
		setLayout(new BorderLayout());

		JPanel parent = new JPanel();
		createTopControls(parent);
		add(parent, BorderLayout.NORTH);

		this.outputPane = JEditorPaneUtil.createRtfCodeEditorPane();
		add(new JScrollPane(this.outputPane), BorderLayout.CENTER);

		this.out = new PrintStream(new JEditorPaneStream(getOutputPane()));
	}

	protected abstract void createTopControls(JPanel parent);

	public JEditorPane getOutputPane() {
		return this.outputPane;
	}

	public PrintStream getOutputStream() {
		return this.out;
	}
}
